package com.repair.project.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.repair.project.config.R;
import com.repair.project.entity.Repaircontent;
import com.repair.project.entity.Student;
import com.repair.project.service.RepaircontentService;
import com.repair.project.service.StudentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hz
 * @since 2021-01-12
 */
@RestController
@RequestMapping("/project/repair")
public class RepaircontentController {

    @Autowired
    RepaircontentService repaircontentService;
    @ApiOperation("接口描述：获取报修信息列表")
    @GetMapping("getRepairList")
    public R getRepairList(@RequestParam(value = "page")int page, @RequestParam(value = "limit")int limit,
                        @RequestParam(required = false, value = "repairid")Integer repairid,
                        @RequestParam(required = false, value = "stuid")Long stuid,
                        @RequestParam(required = false, value = "workerid")Integer workerid,
                        @RequestParam(required = false, value = "houseid")Integer houseid,
                        @RequestParam(required = false, value = "typeid")Integer typeid,
                        @RequestParam(required = false, value = "name")String name,
                        @RequestParam(required = false, value = "status")String status
    ){
        PageHelper.startPage(page,limit);
        List<Map<String,Object>> list = repaircontentService.getRepairList(repairid,stuid,workerid,houseid,typeid,name,status);
        PageInfo<Map<String,Object>> pageInfo = new PageInfo<Map<String,Object>>(list);
        Map<String,Object> data=new HashMap<>();//装载分页数据
        data.put("data",pageInfo.getList());//数据
        return R.ok().data("datalist",pageInfo);
    }



    @ApiOperation("接口描述:增加报修单")
    @PostMapping("addRep")
    public R addStus(@RequestBody Repaircontent repaircontent){
        return R.ok().data("data",repaircontentService.save(repaircontent));
    }

    @ApiOperation("接口描述：删除报修")
    @GetMapping("delRep")
    public R delRep(@RequestParam(value = "repairid")int repairid){
        return R.ok().data("data",repaircontentService.removeById(repairid));
    }

    @ApiOperation("接口描述：更新保修单")
    @PostMapping("updRep")
    public R updRep(@RequestBody Repaircontent repaircontent){
        return R.ok().data("data",repaircontentService.updateById(repaircontent));
    }




}

